package com.jxltech.unicam.utils;

import java.io.*;

import cn.hutool.core.util.RandomUtil;
import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.*;

/***
 - 音乐播放器类
 - @author lt
 - time 2016-7-5
 */
public class AudioPlayer {
	private static AudioPlayer passPlayer = new AudioPlayer("pass.mp3");
	private static AudioPlayer failPlayer = new AudioPlayer("fail.mp3");
	private String music;

	//构造方法  参数是一个.mp3音频文件
	public AudioPlayer(String fileName) {
		music = fileName;
	}

	//播放方法
	public void play() {
			try{
				InputStream inStream = AudioPlayer.class.getClassLoader().getResourceAsStream(music);
				assert inStream != null;
				Player player = new Player(inStream);
				player.play();
			} catch (JavaLayerException e) {
				e.printStackTrace();
			}

	}

	public static void pass() {
		passPlayer.play();
	}

	public static void fail()  {
		failPlayer.play();
	}

	public static void main(String[] s) {
		for (int i = 0; i < 50; i++) {
			System.out.println();
		}
		if (RandomUtil.randomInt(2) == 0)
			pass();
		else
			fail();
	}
}
